package com.sdhs.paas.gateway.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.Feature;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.ToStringSerializer;

public class JSONUtil
{
  public static String obj2json(Object object)
  {
    SerializeConfig serializeConfig = new SerializeConfig();
    serializeConfig.put(Long.class, ToStringSerializer.instance);
    return JSON.toJSONString(object, serializeConfig, new SerializerFeature[0]);
  }

  public static <T> T json2obj(String json, Class<T> clazz)
  {
    return JSON.parseObject(json, clazz);
  }

  public static <T> T json2obj(String json, TypeReference<T> type)
  {
    return JSON.parseObject(json, type, new Feature[0]);
  }
}